package donajurema;

import java.text.SimpleDateFormat;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import donajurema.model.Product;

public class TableLabelProvider extends LabelProvider implements ITableLabelProvider 
{

    SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
	
	public Image getColumnImage(Object element, int columnIndex) 
	{
		return null;
	}
	
	public String getColumnText(Object element, int columnIndex) 
	{
		Product p = (Product)element;
		String result = "";
		switch(columnIndex){
		case 0:
			result = p.getName();
			break;
		case 1:
			result = p.getQuantity().toString();
			break;
		case 2:
			result = p.getUnit().toString();
			break;
		case 3:
			result = p.getShop();
			break;
		case 4:
			result = dateformat.format(p.getDate());
			break;
		default:
			//should not reach here
			result = "";
		}
		return result;
	}
}